import static com.googlecode.javacv.cpp.opencv_core.cvGetSize;
import static com.googlecode.javacv.cpp.opencv_features2d.drawKeypoints;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_COLOR;
import static opencvtest.OpenCVUtils.loadAndShowOrExit;
import static opencvtest.OpenCVUtils.show;

import java.io.File;

import com.googlecode.javacv.cpp.opencv_core.CvMat;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_features2d.DescriptorExtractor;
import com.googlecode.javacv.cpp.opencv_features2d.DrawMatchesFlags;
import com.googlecode.javacv.cpp.opencv_features2d.KeyPoint;
import com.googlecode.javacv.cpp.opencv_nonfree.SIFT;

/**    
 * 文件名：JavaCvSift2.java    
 *    
 * 版本信息：    
 * 日期：2014年3月12日    
 * xyj 足下 xyj 2014     
 * 版权所有    
 *    
 */

/**
 * @项目名称：opencv-test
 * @类名称：JavaCvSift2
 * @类描述：
 * @创建人：zhuyi
 * @创建时间：2014年3月12日 下午4:04:24
 * @修改人：zhuyi
 * @修改时间：2014年3月12日 下午4:04:24
 * @修改备注：
 * @version
 * 
 */
public class JavaCvSift2 {

    public static void main(String[] args) {
        IplImage image = loadAndShowOrExit(new File("E:/image-test/s2.jpg"), CV_LOAD_IMAGE_COLOR);

        KeyPoint keyPoints = new KeyPoint();
        int nFeatures = 0;
        int nOctaveLayers = 3;
        float contrastThreshold = 0.03f;
        int edgeThreshold = 10;
        float sigma = 1.6f;
        SIFT sift = new SIFT(nFeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma);
        DescriptorExtractor siftDesc = DescriptorExtractor.create("SIFT");
        sift.detect(image, null, keyPoints);
        CvMat descriptors = new CvMat(null);
        siftDesc.compute(image, keyPoints, descriptors);

        IplImage featureImage = IplImage.create(cvGetSize(image), image.depth(), 3);
        drawKeypoints(image, keyPoints, featureImage, CvScalar.RED, DrawMatchesFlags.DRAW_RICH_KEYPOINTS);
        show(featureImage, "SIFT Features");
    }

}
